package jgl.vajra.operator.part.mine.activity;

import jgl.vajra.operator.R;
import jgl.vajra.operator.databinding.ActivitySettingPageBinding;
import jgl.vajra.operator.manager.AccountManager;
import jgl.vajra.operator.manager.IntentManager;
import jgl.vajra.operator.netty.ImConnection;
import jgl.vajra.operator.part.home.activity.HomeActivity;
import jgl.vajra.operator.part.mine.contract.SettingPageContract;
import jgl.vajra.operator.part.mine.pop.SharePop;
import jgl.vajra.operator.part.mine.viewModel.SettingPageViewModel;
import jgl.vajra.operator.widget.manager.SPManager;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.AppActivityManager;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.utils.AppUtils;
import jgl.vajra.operator.widget.utils.ToastUtils;

@CreateViewModel(SettingPageViewModel.class)
public class SettingPageActivity extends BaseMVVMActivity<SettingPageViewModel, ActivitySettingPageBinding> implements SettingPageContract.View {

    private SharePop sharePop;
    private boolean isSwitch;

    @Override
    public int getLayoutId() {
        return R.layout.activity_setting_page;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        mBinding.tvVersion.setText(AppUtils.getAppInfo().getVersionName());

        isSwitch = SPManager.MineData.getVoicePlayback();
        mBinding.ivSwitch.setImageResource(isSwitch ? R.drawable.ic_setting_open : R.drawable.ic_setting_shut);
    }


    //个人信息
    @Override
    public void onPersonalInformation() {
        IntentManager.toPersonalInformationActivity(this);
    }

    //账号
    @Override
    public void onAccount() {
        IntentManager.toAccountPageActivity(this);
    }

    //紧急联系人
    @Override
    public void onEmergencyContact() {
        IntentManager.toEmergencyContactActivity(this);
    }

    //评价
    @Override
    public void onEvaluate() {

    }

    //分享
    @Override
    public void onShare() {
        if (sharePop == null) {
            sharePop = new SharePop(this);
        }
        sharePop.showPopupWindow(mBinding.getRoot());
    }

    //金钢佬法律条款
    @Override
    public void onLegalProvisions() {
        IntentManager.toLegalProvisionsActivity(this);
    }

    //语言播报
    @Override
    public void onVoiceAnnouncements() {
        isSwitch = !isSwitch;
        SPManager.MineData.saveVoicePlayback(isSwitch);
        mBinding.ivSwitch.setImageResource(isSwitch ? R.drawable.ic_setting_open : R.drawable.ic_setting_shut);
    }

    //版本号
    @Override
    public void onVersion() {
        AccountManager.getInstance().getVersionUpdate(this);
    }

    //退出登录
    @Override
    public void onSignOutAccount() {
        ImConnection.getInstance().close();
        SPManager.LoginData.setIsLogin(false);
        AccountManager.getInstance().logout(this);
        IntentManager.toLoginActivity(this);
        AppActivityManager.getAppActivityManager().finishActivity(HomeActivity.class);
        finish();
    }
}
